cmake_minimum_required(VERSION 3.20)
project(thread_pool VERSION 1.0.0)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)

# spdlog
FetchContent_Declare(
        spdlog
        URL https://github.com/gabime/spdlog/archive/refs/tags/v1.14.1.zip
        DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
FetchContent_MakeAvailable(spdlog)

# thread_pool
message(STATUS "Build thread_pool: " ${PROJECT_VERSION})
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src src_list)
add_library(${PROJECT_NAME} ${src_list})
target_link_libraries(${PROJECT_NAME} PRIVATE pthread)
target_include_directories(${PROJECT_NAME} PRIVATE ${spdlog_SOURCE_DIR}/include)
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/include> $<INSTALL_INTERFACE:include>)

# example
add_subdirectory(example)

if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
    option(${PROJECT_NAME}_install "Enable installation of ${PROJECT_NAME}." ON)
    option(${PROJECT_NAME}_test "Generate the test target." ON)
endif ()

# install
if (${PROJECT_NAME}_install)
    include(install.cmake)
endif ()

# test
if (${PROJECT_NAME}_test)
    option(INSTALL_GTEST "Enable installation of googletest." OFF)
    FetchContent_Declare(
            googletest
            URL https://github.com/google/googletest/archive/refs/tags/v1.15.0.zip
            DOWNLOAD_EXTRACT_TIMESTAMP TRUE
    )
    FetchContent_MakeAvailable(googletest)

    enable_testing()
    add_subdirectory(tests)
endif ()
